package com.login.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.CookieValue;

import com.entity.Ope;
import com.login.entity.JsonLogin;
import com.login.entity.LoginPowerMenu;
import com.login.service.LoginService;
import com.utils.JsonResult;

/**
 * @author 孙梦楠
 * @date 2017年7月12日 下午6:39:55
 * @version V1.0.0
 */

@RestController
@RequestMapping(value = "")
public class LoginController {

	@Autowired
	private LoginService loginservice;

	// 增加
	@RequestMapping(value = "/addope", method = RequestMethod.POST)
	public JsonResult<Ope> addope(@RequestParam("opecode") String opecode,
			@RequestParam("opepassword") String opepassword) {

		return loginservice.addope(opecode, opepassword);

	}

	// 登录页面 先看有没有cookie，如果有，登录已经成功
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public JsonResult<Ope> login(@CookieValue(value = "opecodecookie", required = false) String opecodecookie,
			@CookieValue(value = "opepasswordcookie", required = false) String opepasswordcookie,
			HttpServletRequest request) {

		return loginservice.logincheck(opecodecookie, opepasswordcookie, request);

	}

	// 登录
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public JsonResult<JsonLogin> login(@RequestParam("opecode") String opecode,
			@RequestParam("opepassword") String opepassword,
			@RequestParam("language") String language,
			@RequestParam("message") String opeverification,
			HttpServletResponse response, HttpServletRequest request)
			throws Exception {
		// 前端传过来账号密码

		return loginservice.login(opecode, opepassword, opeverification,language,response, request);

	}
	
	
	

	// 验证短信验证码

//	@RequestMapping(value = "/login/verification", method = RequestMethod.POST)
//	public JsonResult<LoginPowerMenu> verificationlogin(@RequestParam("opeverification") String opeverification,
//			@CookieValue(value = "opecodecookie", required = false) String opecodecookie, HttpServletRequest request) {
//
//		return loginservice.verificationlogin(opeverification, opecodecookie, request);
//
//	}

}
